package com.vitaf.cash.app.sdk.analyse.util

import com.vitaf.cash.app.configs.GombeCreditApiUrl
import com.vitaf.cash.app.request.HttpHelper
import com.vitaf.cash.app.request.IHttpCallback
import com.vitaf.cash.app.sdk.analyse.GombeCreditAnalyseBuilder
import com.vitaf.cash.app.utils.log.VitafLog
import org.json.JSONObject


object UrlHelper {

    fun combineUrl(): String {
        if (GombeCreditAnalyseBuilder.host.isBlank() or
            GombeCreditAnalyseBuilder.zone.isBlank() or
            GombeCreditAnalyseBuilder.pathCommon.isBlank()
        ) {
            return ""
        }

        val zone = GombeCreditAnalyseBuilder.zone
        GombeCreditAnalyseBuilder.zone = zone.replace("/", "")

        val pathCommon = GombeCreditAnalyseBuilder.pathCommon
        GombeCreditAnalyseBuilder.pathCommon = if (pathCommon.startsWith("/")) {
            pathCommon.replace("/", "")
        } else {
            pathCommon
        }
        return GombeCreditApiUrl.takeRequestUrl()
    }
}

object AnalyseRequestUtil {
    fun doPostAction(toUrl: String, body: String) {
        if (toUrl.isBlank()) return
        if (body.isBlank()) return

        VitafLog.i("Analyse Url：  $toUrl")
        VitafLog.i("Analyse Params： $body")
        HttpHelper.post(toUrl,JSONObject(body),object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
            }
        })
    }
}


